Skip to content

Faster thread local random for inserts#15

Merged
panmari merged 2 commits intomasterfrom
fastrand
Sep 26, 2023
Merged

Faster thread local random for inserts#15
panmari merged 2 commits intomasterfrom
fastrand

Conversation

@panmari
Copy link
Owner

@panmari panmari commented Sep 22, 2023

Avoid costly global random calls.

Avoids making use of a global lock. Slighlty faster in benchmarks, but
for most cases construction time doesn't matter and is bottle necked on
reading input anyway.

benchstat master_gotip.bench fastrand_gotip.bench
name             old time/op  new time/op  delta
Filter_Reset-4   2.58µs ± 4%  2.61µs ±13%   ~     (p=0.841 n=5+5)
Filter_Insert-4  37.8ns ± 7%  35.9ns ± 0%   ~     (p=0.190 n=5+4)
Filter_Lookup-4  37.7ns ± 6%  37.6ns ± 3%   ~     (p=0.841 n=5+5)
@kentquirk
Copy link

Sorry I couldn't respond earlier. I'll resubmit a PR with the subset you requested in #13.

I gotta say, though, personally I'd much sooner take another dependency than use unsafe to link to a part of the go runtime that could fail in some future release of Go.

Since this code already has go-metro, I could rework #13 to use that instead of wyhash to get the same result without a new dependency. If you're interested, I could have that done this weekend.

@panmari
Copy link
Owner Author

panmari commented Sep 26, 2023

You're bringing up some good points, the things that in the end swayed me towards runtime.fastrandn were

  • Stability throughout the last go releases, unlikely to change at this point.
  • In a corp environment, adding additional dependencies comes with a non-trivial review process.
  • Trust in developers: I have to do less reviewing/additional testing myself for runtime.fastrandn, because it was developped by the core go team.

I hope that makes sense.

@panmari panmari merged commit 5d2f798 into master Sep 26, 2023
@panmari panmari deleted the fastrand branch March 17, 2024 18:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants